import apiData  from './apiData.js';

export default {
	// timeFormat: function(type) {
	// 	if (type == 1) {
	// 		let data = new Date().getFullYear() + '-' + (new Date().getMonth() + 1) + '-' + new Date().getDate() +
	// 			'日'
	// 		return data
	// 	} else {
	// 		let data = new Date().getFullYear() + '年' + (new Date().getMonth() + 1) + '月' + new Date().getDate() +
	// 			'日'
	// 		return data
	// 	}
	// },
	compare:function(property){
	    return function(a,b){
	        var value1 =new Date( a[property]).getTime();
	        var value2 = new Date( b[property]).getTime();
	        return value2 - value1;//升序,降序为value2 - value1
	    }
	},//排序，property以数组的某个字段
	getDateBytimeTamp:function(num){
		var dd = new Date(num);
		var y = dd.getFullYear();
		var m = dd.getMonth() + 1;
		var d = dd.getDate();
		var h = dd.getHours();
		var i = dd.getMinutes();
		var s = dd.getSeconds();
		m = m < 10 ? '0' + m : m;
		d = d < 10 ? '0' + d : d;
		return  y + '-' + m + '-' + d 
	},
	getDateDiff:function(checked_in) {
	let str = checked_in.replace(/\-/g, "/");
	return str
	},
	dataFormat:function (num,type) {
		var dd = new Date(num.replace(/-/g,'/'));
		var y = dd.getFullYear();
		var m = dd.getMonth() + 1;
		var d = dd.getDate();
		var h = dd.getHours();
		var i = dd.getMinutes();
		var s = dd.getSeconds();
		m = m < 10 ? '0' + m : m;
		d = d < 10 ? '0' + d : d;
		h = h < 10 ? '0' + h : h;
		i = i < 10 ? '0' + i : i;
		s = s < 10 ? '0' + s : s;
		return  y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s;
	},
	ramdom:function(m,n){
	　　var num = Math.floor(Math.random()*(m - n) + n);
		return num
	},//取随机数
	getNowTime: function () {
	      let dateTime
	      let yy = new Date().getFullYear()
	      let mm = (new Date().getMonth() + 1)<10?'0'+(new Date().getMonth()+1):(new Date().getMonth() + 1)
	      let dd = new Date().getDate()< 10 ? '0'+new Date().getDate():new Date().getDate()
	      let hh = new Date().getHours()< 10 ? '0'+new Date().getHours():new Date().getHours()
	      let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes():new Date().getMinutes()
	       
	      let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds():new Date().getSeconds()
	
	      dateTime = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss
	      return dateTime
	},
	toDecimal2:function (x) {
		//保留两位小数
	           var f = parseFloat(x);
	           if (isNaN(f)) {
	            return false;
	           }
	           var f = Math.round(x*100)/100;
	           var s = f.toString();
	           var rs = s.indexOf('.');
	           if (rs < 0) {
	            rs = s.length;
	            s += '.';
	           }
	           while (s.length <= rs + 2) {
	            s += '0';
	           }
	           return s;
	 },
	getLeavetyoe:function(leaveArr,pk_leaveType){
			let leaveTypeStr //返回的中文
			let filterLeaveShift = leaveArr.filter(item2=>item2.value==pk_leaveType)
			if(filterLeaveShift.length==0){
				leaveTypeStr = '未知'
			}else{
				leaveTypeStr = filterLeaveShift[0].label
			}
		return leaveTypeStr
	},
	getColorByType: function(str) {
		let color
		let data = [{
				titel: '出勤',
				color: "#55aaff"
			},
			{
				titel: '出勤天数',
				color: "#55aaff"
			},
			{
				titel: '年休假',
				color: "#FF2B82"
			},
			{
				titel: '半日年休假',
				color: "#ad1d59"
			},
			{
				titel: '丧假',
				color: "#7c7c32"
			},
			{
				titel: '探亲假',
				color: "#ffaa00"
			},
			{
				titel: '陪护假',
				color: "#2a9a87"
			},
			{
				titel: '公派国外进修',
				color: "#53ffaf"
			},
			{
				titel: '公派国内进修',
				color: "#206243"
			},
			{
				titel: '借调到其他单位',
				color: "#ff2768"
			},
			{
				titel: '半日事假',
				color: "#472fff"
			},
			{
				titel: '下乡',
				color: "#229940"
			},
			{
				titel: '婚假',
				color: "#ffb8b8"
			},
			{
				titel: '放射保健假',
				color: "#ff53a6"
			},
			{
				titel: '探亲假',
				color: "#e1c555"
			},
			{
				titel: '病假',
				color: "#d11de1"
			},
			{
				titel: '工人周末加班',
				color: "#11a6d3"
			},
			{
				titel: '工人平日加班',
				color: "#33768b"
			},
			{
				titel: '自费国外进修',
				color: "#365d9c"
			},
			{
				titel: '上研',
				color: "#7e7742"
			},
			{
				titel: '旷工',
				color: "#e10003"
			},
			{
				titel: '事假',
				color: "#e14e30"
			},
			{
				titel: '产假',
				color: "#55e14b"
			},
			{
				titel: '计划生育假',
				color: "#4e8d47"
			},
			{
				titel: '产假',
				color: "#27cf9d"
			},
			{
				titel: '脱产攻读学位',
				color: "#7139e1"
			},
			{
				titel: '脱产攻读硕士',
				color: "#3c2db3"
			},
			{
				titel: '节假日加班/天',
				color: "#3d5e50"
			},
			{
				titel: '进修博士后流动站',
				color: "#e1d2a3"
			},
		]
		let newData = data.filter(item =>str.indexOf(item.titel) != -1)

		if (newData.length == '0') {
			color = "#000000"
		} else {
			color = newData[0].color
		}
		if (str == 'leave') {
			return data
		} else {
			return color
		}
	}, //图标与日历的请假类型颜色，若data里面没有这个类型那么返回的是全黑色。里面的颜色与值 和calender，chart 相关联
	queryDatae: function(value, list) {
		let len = list.length;
		let arr = [];
		for (let i = 0; i < len; i++) {
			//如果字符串中不包含目标字符会返回-1
			if (list[i].message.indexOf(value)!= -1) {
				arr.push(list[i]);
			}
		}
		return arr
	}
}
